#include <pthread.h>
#include <stdio.h>

void *threadSafe(void *args){
    int *threadId = (int *)args;
    printf("Hello from thread: %d\n", *threadId);
}

int main(){

    int i,j;

    int NUM_THREADS = 10;
    pthread_t threads[NUM_THREADS];
    int thread_args[NUM_THREADS];

    printf("Not in thread!\n");

    // 创建10个线程
    for (i = 0;i < NUM_THREADS; i++) {

        thread_args[i] = i;
        pthread_create(&threads[i], NULL, threadSafe,(void *)&thread_args[i]);
    }
    for (j = 0;j < NUM_THREADS; j++) {
        pthread_join(threads[j],NULL);
    }
    // 等待10个线程完成
    printf("After thread!\n");

    pthread_exit(NULL);

    return 0;
}